﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MJM.SPP.EntidadesNegocio;
using MJM.Principal;

namespace wRegPadron.frmOpciones
{
    public partial class ucMoverModulo : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SubOpcionEN objSubOpcionEN = MediadorCN.GetSubOpcion().ObtenerTexto("MenuMoverModulos");
                lblTitulo.Text = objSubOpcionEN.SUBOPT_chNOMSOP;
                lblDescripcion.Text = objSubOpcionEN.SUBOPT_chDESSOP;

                gvItems.DataSource = MediadorCN.GetNodo().Listar(1, txtFiltro.Text);
                gvItems.DataBind();

                gvPadres.DataSource = "";
                gvPadres.DataBind();
            }
        }

        protected void btnFiltrar_Click(object sender, ImageClickEventArgs e)
        {
            int opt = 0;
            if (rbModulo.Checked)
                opt = 1;
            if (rbOpcion.Checked)
                opt = 2;
            if (rbControl.Checked)
                opt = 3;
            gvItems.DataSource = MediadorCN.GetNodo().Listar(opt, txtFiltro.Text);
            gvItems.DataBind();
        }

        protected void gvItems_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Seleccionar")
            {
                hfIdElemento.Value = Server.HtmlDecode(gvItems.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text);
                txtFiltro.Text = Server.HtmlDecode(gvItems.Rows[Convert.ToInt32(e.CommandArgument)].Cells[1].Text);
            }
        }

        protected void gvItems_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            int opt = 0;
            if (rbModulo.Checked)
                opt = 1;
            if (rbOpcion.Checked)
                opt = 2;
            if (rbControl.Checked)
                opt = 3;
            gvItems.PageIndex = e.NewPageIndex;
            gvItems.DataSource = MediadorCN.GetNodo().Listar(opt, txtFiltro.Text);
            gvItems.DataBind();
        }
    }
}